package com.dyit.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class RabbitMqConfig {
    public static final String TOPIC_EXCHANGE = "my_topic_exchange";

    public static final String TOP_QUEUE_A="queue_a";
    public static final String TOP_QUEUE_B="queue_b";

    public static final String ROUTING_KEY_A = "apple.topic.*";
    public static final String ROUTING_KEY_B = "*.topic.*";


    public static final String DIRECT_EXCHANGE = "direct_exchange";
    public static final String DIRECT_QUEUE = "websocket_queue";
    public static final String ROUTING_KEY = "websocket_routing_key";



    @Resource
    private Queue directQueue;

    @Resource
    private DirectExchange directExchange;
    @Bean
    public Binding directBinding(){
        return BindingBuilder
                .bind(directQueue)
                .to(directExchange)
                .with(RabbitMqConfig.ROUTING_KEY);
    }

    @Autowired
    private QueueConfig queueConfig;
    @Autowired
    private ExchangeConfig exchangeConfig;
    @Bean
    public Binding bindingTopA(){
        return BindingBuilder.bind(queueConfig.topicQueueA())
                .to(exchangeConfig.topicExchange())
                .with(RabbitMqConfig.ROUTING_KEY_A);
    }
    @Bean
    public Binding bindingTopB(){
        return BindingBuilder.bind(queueConfig.topicQueueB())
                .to(exchangeConfig.topicExchange())
                .with(RabbitMqConfig.ROUTING_KEY_B);
    }
}
